package com.tuanchauict.android.englishtip.activities;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

import com.tuanchauict.android.englishtip.R;
import com.tuanchauict.android.englishtip.database.Word;

public class WordAdapter extends ArrayAdapter<Word> {
	
	private List<Word> words;
	private Activity context;
	private ImageButton btnEdit;
	private ImageButton btnDel;
	private TextView txtWord;
	
	public WordAdapter(Context context, List<Word> words){
		super(context, R.layout.word_item, words);
		this.words = words;
		this.context = (Activity) context;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		
		if(row == null){
			LayoutInflater inflater = context.getLayoutInflater();
			row = inflater.inflate(R.layout.word_item, null);
			
		}
		
		txtWord = (TextView) row.findViewById(R.id.word_item_text);
		btnEdit = (ImageButton) row.findViewById(R.id.word_item_edit);
		btnDel = (ImageButton) row.findViewById(R.id.word_item_remove);
		
		Word w = words.get(position);
		txtWord.setText(w.getWord());
		
		
		return row;
	}
}
